/*
 * LCD1602 I2C
   DHT11
 */

#ifndef LCD1602A_I2C_DHT11_H
#define LCD1602A_I2C_DHT11_H

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "component_dht11.h"

long previousMillis_temp;
const int interval_temp = 1000;

LiquidCrystal_I2C lcd(0x27, 16, 2); // 配置LCD地址及行列

void setup_lcd1602a_i2c_dht11()
{
  lcd.init();                  // 初始化LCD
  lcd.backlight();             // 打开背光
  lcd.setCursor(0, 0);         // 设置显示位置
  lcd.print("Welcome To");     // 显示字符数据
  lcd.setCursor(0, 1);         // 设置显示位置
  lcd.print(" Arduino World"); // 显示字符数据
  delay(1000);
}

void loop_lcd1602a_i2c_dht11()
{
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis_temp >= interval_temp)
  {
    previousMillis_temp = currentMillis; // Remember the time
    dht11_on();
    Serial.print("temp:");
    Serial.print(temperature);
    Serial.print("  humi:");
    Serial.println(humidity);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Temperature: ");
    lcd.print(temperature);
    lcd.setCursor(3, 1);
    lcd.print("Humidity: ");
    lcd.print(humidity);
  }
}

#endif /*  LCD1602A_I2C_DHT11_H */